{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# methods "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "lst = [1,2,3,4,5,6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "lst.append(12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(lst.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "dit = {\"key1\":1,\"key2\":2}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Functions ?\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. We use functions for breaking the big peice of code to small manageable codes \n",
    "\n",
    "2. we use functions for code reusablity, \n",
    "\n",
    "3. we use function for recuding down the memory usage. \n",
    "\n",
    "4. We use function for reducing time and efforts \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "# How to write our first function in Python \n",
    "\n",
    "def someFunction():\n",
    "    '''\n",
    "    Hey this function is there for our understanding !! :)\n",
    "    '''\n",
    "    print(\"Hey Hi i am a peice of module - \")\n",
    "    print(\"I am another line from the code\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hey Hi i am a peice of module - \n",
      "I am another line from the code\n"
     ]
    }
   ],
   "source": [
    "# How to call a function\n",
    "\n",
    "someFunction()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function __main__.someFunction()>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# if u dont write () in the end what happens ?\n",
    "someFunction\n",
    "# It prints ur Address of the function from the memory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hey Hi i am a peice of module - \n",
      "I am another line from the code\n"
     ]
    }
   ],
   "source": [
    "someFunction()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function someFunction in module __main__:\n",
      "\n",
      "someFunction()\n",
      "    Doc String for expanations\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(someFunction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function someFunction in module __main__:\n",
      "\n",
      "someFunction()\n",
      "    Hey this function is there for our understanding !! :)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(someFunction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "#How to take a aurgument for my functionm\n",
    "\n",
    "def someFunction(thisIsOurAurgument, ourSecAurgument):\n",
    "    '''\n",
    "    Hey this function is there for our understanding !! :)\n",
    "    '''\n",
    "    print(\"Hey Hi i am a peice of module - \", thisIsOurAurgument)\n",
    "    print(\"I am another line from the code - \", ourSecAurgument)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hey Hi i am a peice of module -   Aditya\n",
      "I am another line from the code Shekhar\n"
     ]
    }
   ],
   "source": [
    "someFunction(\" Aditya\", \"Shekhar\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "#How can our Fun. return a value ?\n",
    "\n",
    "def playingMyFavSong(songNo):\n",
    "    '''\n",
    "    This function suggest u a song\n",
    "    '''\n",
    "    if songNo == 1:\n",
    "        return \"Despacito\"\n",
    "    elif songNo == 2:\n",
    "        return \"Samajavagamana\"\n",
    "    elif songNo == 3 :\n",
    "        return \"Dil Se\"\n",
    "    elif songNo == 4 :\n",
    "        return \"Chogada Tara\"\n",
    "    elif songNo == 5 :\n",
    "        return \"Chinamma Chinamma\"       \n",
    "    elif songNo == 6 :\n",
    "        return \"Zinggant\"\n",
    "    else:\n",
    "        return \"Listen to Faded\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Chinamma Chinamma'"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "playingMyFavSong(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Zinggant'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "playingMyFavSong(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "from random import randint\n",
    "\n",
    "# this function is returing A Random Odd Number\n",
    "\n",
    "def getUsARamdomOddNumber():\n",
    "    value = randint(2, 100)\n",
    "    if value % 2 == 0:\n",
    "        value = value -1\n",
    "    return value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "97"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "getUsARamdomOddNumber()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "# We need to make a function which actually get two random odd numbers \n",
    "# then multiple it and return the number\n",
    "\n",
    "def multipleTwoRandomOddNumber():\n",
    "    value1 = getUsARamdomOddNumber()\n",
    "    value2 = getUsARamdomOddNumber()\n",
    "    print(value1,'   ', value2)\n",
    "    return value1 * value2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "57     85\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "4845"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "multipleTwoRandomOddNumber()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [],
   "source": [
    "# if you wish to take N number of Arguments in the python function, \n",
    "\n",
    "# how to do take \n",
    "\n",
    "def takeN_NumberOfAurguments(*sgra):\n",
    "    for i in sgra:\n",
    "        print(\"Args which we got -  \",i) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Args which we got -   HI\n",
      "Args which we got -   [1, 2, 3]\n",
      "Args which we got -   {'key1': 1, 'key2': 2}\n",
      "Args which we got -   4\n",
      "Args which we got -   I Hope u are understanding ?\n"
     ]
    }
   ],
   "source": [
    "takeN_NumberOfAurguments(\"HI\",[1,2,3],{'key1':1,\"key2\":2},4,\"I Hope u are understanding ?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "# If u want to pass multiple Arguments into the function \n",
    "# But want to have a variable name for each one of the aurgument a\n",
    "# just like how we use in Dict \n",
    "# then we should look at **KWARGS \n",
    "\n",
    "def takeMultipleKeyValueArgs(**agrawk):\n",
    "    for key, value in agrawk.items():\n",
    "        print(\"The Key - [\", key,\"] The Val - [\",value,\" ]\")\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Key - [ name ] The Val - [ LetsUpgrade  ]\n",
      "The Key - [ age ] The Val - [ 2  ]\n",
      "The Key - [ dob ] The Val - [ 8th May 2018  ]\n"
     ]
    }
   ],
   "source": [
    "takeMultipleKeyValueArgs(name= \"LetsUpgrade\", age = 2, dob = \"8th May 2018\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [],
   "source": [
    "# *args is used of passing multiplew value, u cant access with name\n",
    "\n",
    "# **kwargs is used for passing multiple Key value pairs to make\n",
    "# sure you can access any value with a name\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "# problem statement is - \n",
    "\n",
    "# Build a Fucntion for sending mails to a specif \n",
    "# email ids given in a argument\n",
    "\n",
    "\n",
    "def sendEmailsToTheListOfPeople(*emailList):\n",
    "    for emails in emailList:\n",
    "        print(\"Email is been sent to  -  \",emails) \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Email is been sent to  -   sai@itm.edu\n",
      "Email is been sent to  -   viralp@itm.edu\n",
      "Email is been sent to  -   amareshb@itm.edu\n",
      "Email is been sent to  -   vishnun@itm.edu\n",
      "Email is been sent to  -   harshrajs@itm.edu\n"
     ]
    }
   ],
   "source": [
    "sendEmailsToTheListOfPeople(\"sai@itm.edu\",\"viralp@itm.edu\",\n",
    "                            \"amareshb@itm.edu\",\"vishnun@itm.edu\",\n",
    "                            \"harshrajs@itm.edu\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Problem statement 2 - \n",
    "\n",
    "# print the name, age and dob of the student in a formatted way \n",
    "\n",
    "#like \n",
    "\n",
    "# ---------------\n",
    "# | Name -       |\n",
    "# | Age -       |\n",
    "# | DOB -       |\n",
    "# ---------------"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [],
   "source": [
    "def printStudentDataInFormat(**studentInfo):\n",
    "    \n",
    "    print(\"------------\")\n",
    "    print(\"Name - \", studentInfo.get(\"name\") )\n",
    "    print(\"Age  - \", studentInfo.get(\"age\") )\n",
    "    print(\"DOB  - \", studentInfo.get(\"dob\") )\n",
    "    print(\"------------\")\n",
    "\n",
    "    \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "------------\n",
      "Name -  Sai\n",
      "Age  -  60\n",
      "DOB  -  01 01 1960\n",
      "------------\n"
     ]
    }
   ],
   "source": [
    "printStudentDataInFormat(name = \"Sai\", age =60,dob = \"01 01 1960\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
